Reference Toolkit
GridAgent
The GridAgent
class represents an agent that operates within a grid world environment. It interacts with the world by moving through cells, avoiding obstacles, and reaching goal states. The agent's behavior is determined by algorithms that guide its actions, such as pathfinding or reinforcement learning.
Attributes
algorithmCallBack: function
- Callback function for the agent's algorithm.
Constructor
The constructor initializes an instance of the GridAgent
class with attributes defining the grid world.
__init__(self, world, agentName:str, agentColor:str="blue", agentPos=None, heatMapView:bool=True, heatMapColor:str="#FFA732", heatGradient:float=0.05)
Usage
GridAgent
class provides methods to control the agent's movement within a grid world, interact with its environment, and visualize heat maps. It serves as a foundation for implementing agent-based simulations and experiments within defined grid-based environments.- Parameters:
world ( CreateGridWorld )
: The grid world object in which the agent operates.agentName (str)
: The name of the agent.agentColor (str, optional)
: The color of the agent. Defaults to "blue".heatMapView (bool, optional)
: Whether to enable the heat map view. Defaults to True.heatMapColor (str, optional)
: The color of the heat map. Defaults to "#FFA732".agentPos (tuple, optional)
: The initial position of the agent. Defaults to (0, 0).heatGradient (float, optional)
: The gradient value for the heat map. Defaults to 0.05.
- Returns: None
- Raises:
ValueError
if rows or columns are out of valid range.
Methods
__str__()
Returns a string describing the attributes of the agent.
Parameters
- None
Returns
str
: Description of the agent's attributes.
aboutAgent()
Prints information about the agent including its name, color, and the world it operates in.
Parameters
- None
Returns
- None
summary()
Returns a summary of the agent's run including start time, end time, and elapsed time.
Parameters
- None
Returns
dict
: Summary of the agent's run.
setStartState(i: int, j: int)
Sets the start state of the agent to the specified position (i, j) on the grid world.
Parameters
i (int)
: The row index of the start position.j (int)
: The column index of the start position.
Returns
- None
Raises
ValueError
: If the specified start position is invalid.
checkBlockState(i: int, j: int)
Checks if the specified position (i, j) in the grid world is a goal state.
Parameters
i (int)
: The row index of the gridWorld state.j (int)
: The column index of the gridWorld state.
Returns
bool
: True if the specified position in the grid world is a goal state, False otherwise.
checkGoalState(i: int, j: int)
Checks if the specified position (i, j) in the grid world is a block state.
Parameters
i (int)
: The row index of the gridWorld state.j (int)
: The column index of the gridWorld state.
Returns
bool
: True if the specified position in the grid world is a block state, False otherwise.
moveAgent(i: int, j: int, delay: float=0.5)
Moves the agent to the specified position (i, j) on the grid world.
Parameters
i (int)
: The row index of the target position.j (int)
: The column index of the target position.delay (float, optional)
: The delay in seconds before moving the agent. Defaults to 0.5 seconds.
Returns
bool
: True if the agent successfully moves to the target position, False otherwise.
Internal Methods
NOTE: These methods are not intended to be directly called by users but support the functionality of the class.
_warmerColor(color: str, sValue: float)
Generates a warmer color from the given color based on saturation value.
runAlgorithm()
Executes the callback function set by setAlgorithmCallBack()
.
Parameters
- None
Returns
- None
Raises
ValueError
: If the callback function is not set.
getHeatMapColor(value: float)
Maps a numeric value to a color on the heat map.
Parameters
value (float)
: The value to be mapped.
Returns
str
: The RGB color string representing the mapped value on the heat map.
_disableCellToggle(self)
Checks if the specified position (i, j) on the grid world is blocked or empty.